package com.wanghlme.bookstore.controller.client;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@RequestMapping("/client")
@Controller
public class BooksController {

    @RequestMapping("/toAddUI")
    public void toAddUI() {

    }
    /*
    *
    * 	public void toAddUI(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
		System.out.println("---BookServlet toAddUI()---");

		List<Category> allCategorys = categoryService.getAllCategorys();
		WebUtils.forword(request, response, "/manager/book/add.jsp", "allCategorys", allCategorys);
	}
	public void add(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
		System.out.println("---BookServlet add()---");

		Book book = WebUtils.uploadBook(request);

		bookService.addBook(book);

		WebUtils.forwordMessageUI(request, response, "添加图书成功！");
	}
	public void listAll(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
		System.out.println("---BookServlet listAll()---");

		List<Book> list = bookService.getAllBooks();
		WebUtils.forword(request, response, "/manager/book/list.jsp", "list", list);
	}
	public void showBook(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
		System.out.println("---BookServlet showBook()---");

		String id = request.getParameter("bookid");
		Book book = bookService.getBookById(id);
		WebUtils.forword(request, response, "/manager/book/book.jsp", "book", book);
	}
	public void delete(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
		System.out.println("---BookServlet delete()---");

		String id = request.getParameter("bookid");
		bookService.deleteBookById(id);
		WebUtils.forwordMessageUI(request, response, "删除图书成功！");
	}
	public void toUpdateUI(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
		System.out.println("---BookServlet toUpdateUI()---");

		String bookid = request.getParameter("bookid");

		List<Category> allCategorys = categoryService.getAllCategorys();
		Book book = bookService.getBookById(bookid);

		request.setAttribute("allCategorys", allCategorys);
		request.setAttribute("book", book);
		request.getRequestDispatcher("/manager/book/update.jsp").forward(request, response);
	}
	public void update(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
		System.out.println("---BookServlet update()---");

		Book book = WebUtils.request2Bean(request, Book.class);
		bookService.updateBook(book);
		WebUtils.forwordMessageUI(request, response, "更新图书成功！");
	}
    *
    * */
}
